package activiti

import system.Department
import system.StaffMember

/**
 * 任务公共字段
 */
class FbhCommtask {
    /*
    发起部分
     */
    /**发起人*/
    StaffMember creater
    /**业务发起人所属部门*/
    Department createrDpt;
    /**发起时间*/
    Date createrTime
    /**流程主题*/
    String title;
    /**流程实例ID*/
    String piid
    /**流程模板名称*/
    String templateName
    /** 流程模板中文名称*/
    String templateNameZh
    /** 流程流水号*/
    Long flowId;

    /** 公共部分 **/
    /** 单据编号*/
    String commtaskCode;
    /**环节任务id*/
    String taskId;
    /**环节任务名称*/
    String htName;
    /**环节任务中文名称*/
    String htNameZh;
    /**环节对应的form 注册的组件名*/
    String formName
    /**操作人*/
    StaffMember operator
    /**操作人部门*/
    Department operatorDepartment
    /**操作时间*/
    Date operateDate
    /**受限时间*/
    Date limitDate
    /**审批结果*/
    String result
    /**审批意见*/
    String opinion
    /** 任务状态 1-暂存；2-完成*/
    int status;
    /**任务到达时间*/
    Date taskDate
    /** 最顶层flowId*/
    Long topFlowId;
    /**创建时间*/
    Date dateCreated
    /**最后更新的时间*/
    Date lastUpdated
    static constraints = {

        commtaskCode nullable: true
        dateCreated nullable: true
        lastUpdated nullable: true
        creater nullable: true
        createrDpt nullable: true
        createrTime nullable: true
        title nullable: true
        piid nullable: true
        templateName nullable: true
        templateNameZh nullable: true
        flowId nullable: true

        piid nullable: true
        taskId nullable: true
        htName nullable: true
        operator nullable: true
        operatorDepartment nullable: true
        operateDate nullable: true
        limitDate nullable: true
        result nullable: true
        opinion nullable: true
        formName nullable: true
        flowId nullable: true
        htNameZh nullable: true
        status nullable: true
        topFlowId nullable: true
        taskDate nullable: true
    }
    static resultList = ["0": '不通过', "1": "通过"]

    /**
     * 添加配置 tablePerHierarchy：
     *   Grails默认使用的映射继承策略会把子类的所有字段合并放到父类对应的表中，这样会导致因过多的继承而
     *   产生较多字段的父表。
     */
    static mapping = {
        table 'FBH_COMMTASK'
        version false
        id generator:'assigned', name:'id'
        cache false//usage:'read-only'
        tablePerHierarchy false
        sort "dateCreated"
    }

    static getResultList1() {
        def aa = []
        resultList.each { entry ->
            aa << entry.key
        }
        return aa.flatten()
    }


    transient utilsService

    def buildDomain() {
        CommonTask commonTask=CommonTask.get(this.id)
        def b = [:] + commonTask.properties
        b.remove('status')
        def param = [allowformat: true, allowprecision: false]
        b = utilsService.truncProp(commonTask, b, param) { amap ->
            amap << ['id': commonTask.id]
        }
        b
    }

    def buildDomainList(list) {
        def rds = []
        list.each {
            CommonTask commonTask=CommonTask.get(it.id)
            def b = [:] + commonTask.properties
            b.remove('status')
            def param = [allowformat: true, allowprecision: false]
            b = utilsService.truncProp(commonTask, b, param) { amap ->
                amap << ['id': commonTask.id]

            }
            rds << b
        }
        return rds
    }
}
